{include file='public/header.html'}

<div class="container mtn">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">修改文档<span class="pull-right"><a href="javascript:history.back(-1);">返回</a></span></h3>
        </div>
        <div class="panel-body">

            <form class="form-horizontal submit-ajax" role="form" action="{:url('edit')}" method="post">
                <input type="hidden" name="id" value="{$vo.id}" />
                <div class="form-group">
                    <label for="title" class="col-sm-1 control-label">*标题</label>
                    <div class="col-sm-11">
                        <input type="text" id="title" name="title" class="form-control" placeholder="请输入文档标题" value="{$vo.title}" />
                    </div>
                </div>
                <div class="form-group">
                    <label for="name" class="col-sm-1 control-label">*名称</label>
                    <div class="col-sm-11">
                        <input type="text" id="name" name="name" class="form-control" placeholder="文件名称(下载用)" value="{$vo.name}" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">封面</label>
                    <div class="col-sm-11">
                        <input type="hidden" id="thumb" name="thumb" value="{$vo.thumb}" />
                        <div id="pic_up" class="thumb">
                            {if empty($vo['thumb']):}
                            <img style="display:none" id="pic" width="90" height="60" alt="thumb" />上传封面
                            <span id="pic_del">删除</span>
                            {else:}
                            <img src="{$vo.thumb}" id="pic" width="90" height="60" alt="thumb" />上传封面
                            <span id="pic_del" style="display:inline;">删除</span>
                            {/if}
                            <input id="upload-input" type="file" accept="image/*" onchange="previewImg(this);">
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label for="summary" class="col-sm-1 control-label">*简介</label>
                    <div class="col-sm-11">
                        <textarea name="summary" id="summary" rows="2" class="form-control" placeholder="请输入文档简介">{$vo.summary}</textarea>
                    </div>
                </div>
                <div class="form-group">
                    <label for="sort" class="col-sm-1 control-label">*排序</label>
                    <div class="col-sm-11">
                        <input type="text" id="sort" name="sort" class="form-control" style="width:auto;" placeholder="请输入排序值" value="{$vo.sort}" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">&nbsp;</label>
                    <div class="col-sm-11">
                        <input type="submit" id="submit" value="修改" class="btn btn-primary" />
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

{include file='public/footer.html'}
<script>
    function previewImg(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function (im) {
                var apiurl = "{:url('api/upload_base64')}";
                var type = 'thumb';
                $.post(apiurl, {base64: im.target.result, type: type}, function (res) {
                    if (res.status == 1) {
                        pic_del($("#pic"));
                        $('#thumb').val(res.data.path);
                        $("#pic").attr("src", res.data.path).show();
                        $('#pic_del').show();
                    }
                }, 'json');
            };
            reader.readAsDataURL(input.files[0]);
            return 1;
        }
    }
    function pic_del(e) {
        var p = e.attr('src');
        $('#thumb').val('');
        $.post("{:url('api/image_del')}", {pic: p}, function (ret) {
        }, 'json');
    }
    $('#pic_del').on('click', function () {
        pic_del($("#pic"));
        $("#pic").attr("src", '').hide();
        $('#pic_del').hide();
    });
</script>
</body>
</html>